<?php
  // please the browser
  @ob_end_clean();
  header("Content-Type: image/png");
  header("Connection: close");
  ob_start();
  readfile('transparent.gif');
  $size = ob_get_length();
  header("Content-Length: $size");
  ob_end_flush(); 
  flush();        
  
  // frequency / load / bandwidth limiter
  function get_last_update_time() {
    return file_get_contents('timestamp.txt');
  }
  
  function set_last_update_time($t) {
    $f = fopen('timestamp.txt', 'w');
    fputs($f, $t);
    fclose($f);
  }

  $now = time();
  $last_update = get_last_update_time();
  // no more than 1x per minute!
  if ($now - $last_update < 20) die();
  
  set_last_update_time($now);

  // now the real stuff starts

  require_once('db.php');
  require_once('friends.php');

  
  initiate_work();  
  
  echo ('- finished!');
  
  
?>
